#include <iostream>
#include <fstream>
#include <fstream>
#include <ctime>

using namespace std;

int shellSort(int arr[], int n)
{

    for (int gap = n/2; gap > 0; gap /= 2)
    {
        for (int i = gap; i < n; i += 1)
        {
            int temp = arr[i];
            int j;
            for (j = i; j >= gap && arr[j - gap] > temp; j -= gap)
                arr[j] = arr[j - gap];
            arr[j] = temp;
        }
    }
    return 0;
}


int main()
{
    const int LEN = 5000;
    int arr[LEN];

    long long _start;
    long long _finish;
    long long _total;


    ifstream f;
    f.open("m1_sorted.txt");

    int k = 0;
    while (!f.eof()){
        f >> arr[k];
        k++;
    }

    f.close();

    _start = clock();

    shellSort(arr,5000);

    _finish = clock();

    cout << _finish - _start << endl;

    int arr2[LEN];
    f.open("m2_sorted.txt");

    k = 0;
    while (!f.eof()){
        f >> arr2[k];
        k++;
    }
    f.close();

    _start = clock();

    shellSort(arr2,5000);

    _finish = clock();

    cout << _finish - _start << endl;

    int arr3[LEN];
    f.open("m3_sorted.txt");

    k = 0;
    while (!f.eof()){
        f >> arr3[k];
        k++;
    }
    f.close();

    _start = clock();

    shellSort(arr3,5000);

    _finish = clock();

    cout << _finish - _start << endl;
}


